﻿using JiaBloggingSite.Core;
using JiaBloggingSite.Core.Objects;
using JiaBloggingSite.Providers;
using Ninject;
using Ninject.Web.Common;
using System.Web.Mvc;
using System.Web.Routing;
using WebMatrix.WebData;

namespace JiaBloggingSite
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode,
    // visit http://go.microsoft.com/?LinkId=9394801
    public class MvcApplication : NinjectHttpApplication
    {
        protected override IKernel CreateKernel()
        {
            var kernel = new StandardKernel();

            kernel.Load(new RepositoryModule());
            kernel.Bind<IBlogRepository>().To<BlogRepository>();
            kernel.Bind<IAuthProvider>().To<AuthProvider>();

            return kernel;
        }

        protected override void OnApplicationStarted()
        {
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            ModelBinders.Binders.Add(typeof(Post), new PostModelBinder(Kernel));
            AuthConfig.RegisterAuth();
 
            WebSecurity.InitializeDatabaseConnection("JiaBlogDbConnString", "ExternalUsers", "UserId", "UserName", true);
            base.OnApplicationStarted();
        }
    }
}